package sh.ds.el.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import sh.ds.el.dao.base.ElDao;
import sh.ds.el.entity.RoleVO;
import sh.ds.el.enums.CommonEnums.VALIDITY;

@Repository
public class RoleDao extends ElDao {

	public List<RoleVO> queryRolesByUserId(Long userId) {
		StringBuffer sql = new StringBuffer();
		List<Object> params = new ArrayList<Object>();
		
		sql.append(" select r.* ");
		sql.append(" from	sm_user u right join sm_user_role ur on u.user_id = ur.user_id ");
		sql.append("		left join sm_role r on ur.role_id = r.role_id ");
		sql.append(" where	u.validity = ? ");
		params.add(VALIDITY.VALID.name());
		sql.append(" and	r.validity = ? ");
		params.add(VALIDITY.VALID.name());
		sql.append(" and	u.user_id = ? ");
		params.add(userId);
		
		return getEntityManager().queryForListBySql(RoleVO.class, sql.toString(), params);
	}
	
}
